from util import *
import sys
import os

test = os.getenv("TESTNAME")

# Breakpoint on return 0;
send_gdb("break 23")
expect_gdb('Breakpoint 1')
send_gdb('c')
expect_gdb('Breakpoint 1')
send_gdb("print/x $xmm0.v16_int8")
expect_gdb("0x1.*0x2.*0x3.*0x4.*0x5.*0x6.*0x7.*0x8.*0x9.*0xa.*0xb.*0xc.*0xd.*0xe.*0xf.*0x10")

send_gdb("print/x $ymm0.v32_int8")
expect_gdb("0x1.*0x2.*0x3.*0x4.*0x5.*0x6.*0x7.*0x8.*0x9.*0xa.*0xb.*0xc.*0xd.*0xe.*0xf.*0x10.*0x11.*0x12.*0x13.*0x14.*0x15.*0x16.*0x17.*0x18.*0x19.*0x1a.*0x1b.*0x1c.*0x1d.*0x1e.*0x1f.*0x20")

send_gdb("print/x $zmm0.v64_int8")
expect_gdb("0x1.*0x2.*0x3.*0x4.*0x5.*0x6.*0x7.*0x8.*0x9.*0xa.*0xb.*0xc.*0xd.*0xe.*0xf.*0x10.*0x11.*0x12.*0x13.*0x14.*0x15.*0x16.*0x17.*0x18.*0x19.*0x1a.*0x1b.*0x1c.*0x1d.*0x1e.*0x1f.*0x20.*0x21.*0x22.*0x23.*0x24.*0x25.*0x26.*0x27.*0x28.*0x29.*0x2a.*0x2b.*0x2c.*0x2d.*0x2e.*0x2f.*0x30.*0x31.*0x32.*0x33.*0x34.*0x35.*0x36.*0x37.*0x38.*0x39.*0x3a.*0x3b.*0x3c.*0x3d.*0x3e.*0x3f.*0x40")

# Breakpoint on return 0;
send_gdb('break 60')
expect_gdb('Breakpoint 2')
send_gdb('c')
expect_gdb('Breakpoint 2')

send_gdb("print/x $xmm0.uint128")
expect_gdb(r"0x1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a")

send_gdb("print/x $ymm0.v2_int128")
expect_gdb(r"0x1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a,\s+0x1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a")

send_gdb("print/x $zmm0.v4_int128")
expect_gdb(r"0x1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a,\s+0x1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a,\s+0x1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a,\s+0x1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a")

regs_per_mode = []

if test[-3:] == "_32":
  regs_per_mode = [4, 7]
else:
  regs_per_mode = [16, 30]

send_gdb(f"print/x $xmm{regs_per_mode[0]}.uint128")
expect_gdb(r"0x5b5b5b5b5b5b5b5b5b5b5b5b5b5b5b5b")

send_gdb(f"print/x $ymm{regs_per_mode[0]}.v2_int128")
expect_gdb(r"0x5b5b5b5b5b5b5b5b5b5b5b5b5b5b5b5b,\s+0x5b5b5b5b5b5b5b5b5b5b5b5b5b5b5b5b")

send_gdb(f"print/x $zmm{regs_per_mode[0]}.v4_int128")
expect_gdb(r"0x5b5b5b5b5b5b5b5b5b5b5b5b5b5b5b5b,\s+0x5b5b5b5b5b5b5b5b5b5b5b5b5b5b5b5b,\s+0x5b5b5b5b5b5b5b5b5b5b5b5b5b5b5b5b,\s+0x5b5b5b5b5b5b5b5b5b5b5b5b5b5b5b5b")

send_gdb(f"print/x $xmm{regs_per_mode[1]}.uint128")
expect_gdb(r"0xffffffffffffffffffffffffffffffff")

send_gdb(f"print/x $ymm{regs_per_mode[1]}.v2_int128")
expect_gdb(r"0xffffffffffffffffffffffffffffffff,\s+0xffffffffffffffffffffffffffffffff")

send_gdb(f"print/x $zmm{regs_per_mode[1]}.v4_int128")
expect_gdb(r"0xffffffffffffffffffffffffffffffff,\s+0xffffffffffffffffffffffffffffffff,\s+0xffffffffffffffffffffffffffffffff,\s+0xffffffffffffffffffffffffffffffff")

send_gdb('c')
ok()
